package practice;

import java.util.*;

public class test2 {

    public void fun() {
        String[] strs = {"A","B","C","D","E","F"};
        //统计入度
        int[] input = new int[26];
        input['E'-'A'] += 2;
        input['C'-'A'] += 2;
        input['D'-'A']++;

        Map<Character, List<Character>> map = new HashMap<>();
        if(map.getOrDefault('B',null) == null) {
            map.put('B',new LinkedList<>());
            map.get('B').add('C');
        }
        if(map.getOrDefault('C',null) == null) {
            map.put('C',new LinkedList<>());
            map.get('C').add('E');
        }
        if(map.getOrDefault('A',null) == null) {
            map.put('A',new LinkedList<>());
            map.get('A').add('D');
            map.get('A').add('C');
        }
        if(map.getOrDefault('E',null) == null) {
            map.put('E',new LinkedList<>());
            map.get('E').add('F');
        }

        if(map.getOrDefault('D',null) == null) {
            map.put('D',new LinkedList<>());
            map.get('D').add('E');
        }
        if(map.getOrDefault('F',null) == null) {
            map.put('F',new LinkedList<>());
        }
        //入度为0的点
        Stack<Character> stack = new Stack<>();
        stack.push('A');
        stack.push('B');
        while(!stack.isEmpty()) {
            char top = stack.pop();
            System.out.print(top + " ");
            List<Character> list = map.getOrDefault(top,null);
            for(Character ch : list) {
                input[ch-'A']--;
                if(input[ch-'A'] == 0) {
                    stack.push(ch);
                }
            }
        }


        if(stack.isEmpty()) {
            System.out.println("不存在循环");
        }else{
            System.out.println("存在循环");
        }

    }

    public static void main(String[] args) {
        test2 t = new test2();
        t.fun();
    }

}
